using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Globalization;
using PickGold.Charting;
using PickGold.Charting.Utilities;

namespace PickGold.Charting.ChartTypes
{
	internal class BarChart : IChartType, IDisposable
	{
		protected BarValueLabelDrawingStyle defLabelDrawingStyle;
		protected bool drawSeriesSideBySide = true;
		protected bool pointLabelsMarkersPresent;
		protected bool useTwoValues;

		public void AddSmartLabelMarkerPositions(CommonElements common, ChartArea area, Series series, ArrayList list)
		{
		}

		public void Dispose()
		{
			this.Dispose(true);
			GC.SuppressFinalize(this);
		}

		protected virtual void Dispose(bool disposing)
		{
		}

		private void DrawLabels3D(ChartArea area, ChartGraphics graph, CommonElements common, RectangleF rectSize, DataPoint3D pointEx, Series ser, double barStartPosition, double barSize, double width, int pointIndex)
		{
			DataPoint dataPoint = pointEx.dataPoint;
			if ((ser.IsValueShownAsLabel || dataPoint.IsValueShownAsLabel) || (dataPoint.Label.Length > 0))
			{
				RectangleF empty = RectangleF.Empty;
				using (StringFormat format = new StringFormat())
				{
					string str;
					if (dataPoint.Label.Length == 0)
					{
						str = ValueConverter.FormatValue(ser.Chart, dataPoint, dataPoint.Tag, this.GetYValue(common, area, ser, dataPoint, pointIndex, 0), dataPoint.LabelFormat, ser.YValueType, ChartElementType.DataPoint);
					}
					else
					{
						str = dataPoint.ReplaceKeywords(dataPoint.Label);
					}
					SizeF size = SizeF.Empty;
					if (((dataPoint.MarkerStyle != MarkerStyle.None) || (dataPoint.MarkerImage.Length > 0)) && ((pointEx.index % ser.MarkerStep) == 0))
					{
						if (dataPoint.MarkerImage.Length == 0)
						{
							size.Width = dataPoint.MarkerSize;
							size.Height = dataPoint.MarkerSize;
						}
						else
						{
							common.ImageLoader.GetAdjustedImageSize(dataPoint.MarkerImage, graph.Graphics, ref size);
						}
						size = graph.GetRelativeSize(size);
					}
					BarValueLabelDrawingStyle defLabelDrawingStyle = this.defLabelDrawingStyle;
					string strA = "";
					if (dataPoint.IsCustomPropertySet("BarLabelStyle"))
					{
						strA = dataPoint["BarLabelStyle"];
					}
					else if (ser.IsCustomPropertySet("BarLabelStyle"))
					{
						strA = ser["BarLabelStyle"];
					}
					if ((strA != null) && (strA.Length > 0))
					{
						if (string.Compare(strA, "Left", StringComparison.OrdinalIgnoreCase) == 0)
						{
							defLabelDrawingStyle = BarValueLabelDrawingStyle.Left;
						}
						else if (string.Compare(strA, "Right", StringComparison.OrdinalIgnoreCase) == 0)
						{
							defLabelDrawingStyle = BarValueLabelDrawingStyle.Right;
						}
						else if (string.Compare(strA, "Center", StringComparison.OrdinalIgnoreCase) == 0)
						{
							defLabelDrawingStyle = BarValueLabelDrawingStyle.Center;
						}
						else if (string.Compare(strA, "Outside", StringComparison.OrdinalIgnoreCase) == 0)
						{
							defLabelDrawingStyle = BarValueLabelDrawingStyle.Outside;
						}
					}
					bool flag = false;
					bool flag2 = false;
					bool flag3 = false;
					float num = 0f;
					while (!flag)
					{
						format.Alignment = StringAlignment.Near;
						format.LineAlignment = StringAlignment.Center;
						if (barStartPosition < barSize)
						{
							empty.X = rectSize.Right;
							empty.Width = area.PlotAreaPosition.Right - rectSize.Right;
						}
						else
						{
							empty.X = area.PlotAreaPosition.X;
							empty.Width = rectSize.X - area.PlotAreaPosition.X;
						}
						empty.Y = rectSize.Y - (((float)width) / 2f);
						empty.Height = rectSize.Height + ((float)width);
						switch (defLabelDrawingStyle)
						{
							case BarValueLabelDrawingStyle.Outside:
								if (!size.IsEmpty)
								{
									empty.Width -= Math.Min(empty.Width, size.Width / 2f);
									if (barStartPosition < barSize)
									{
										empty.X += Math.Min(empty.Width, size.Width / 2f);
									}
								}
								break;

							case BarValueLabelDrawingStyle.Left:
								empty = rectSize;
								format.Alignment = StringAlignment.Near;
								break;

							case BarValueLabelDrawingStyle.Center:
								empty = rectSize;
								format.Alignment = StringAlignment.Center;
								break;

							case BarValueLabelDrawingStyle.Right:
								empty = rectSize;
								format.Alignment = StringAlignment.Far;
								if (!size.IsEmpty)
								{
									empty.Width -= Math.Min(empty.Width, size.Width / 2f);
									if (barStartPosition >= barSize)
									{
										empty.X += Math.Min(empty.Width, size.Width / 2f);
									}
								}
								break;
						}
						if (barStartPosition >= barSize)
						{
							if (format.Alignment == StringAlignment.Far)
							{
								format.Alignment = StringAlignment.Near;
							}
							else if (format.Alignment == StringAlignment.Near)
							{
								format.Alignment = StringAlignment.Far;
							}
						}
						SizeF ef3 = graph.MeasureStringRel(str, dataPoint.Font);
						if ((!flag2 && !flag3) && (ef3.Width > empty.Width))
						{
							flag2 = true;
							num = empty.Width;
							if (defLabelDrawingStyle == BarValueLabelDrawingStyle.Outside)
							{
								defLabelDrawingStyle = BarValueLabelDrawingStyle.Right;
							}
							else
							{
								defLabelDrawingStyle = BarValueLabelDrawingStyle.Outside;
							}
						}
						else
						{
							if ((flag2 && !flag3) && ((ef3.Width > (empty.Width - 1f)) && (num > empty.Width)))
							{
								flag3 = true;
								if (defLabelDrawingStyle == BarValueLabelDrawingStyle.Outside)
								{
									defLabelDrawingStyle = BarValueLabelDrawingStyle.Right;
								}
								else
								{
									defLabelDrawingStyle = BarValueLabelDrawingStyle.Outside;
								}
								continue;
							}
							flag = true;
						}
					}
					SizeF ef4 = graph.MeasureStringRel(str, dataPoint.Font, new SizeF(empty.Width, empty.Height), format);
					PointF position = PointF.Empty;
					if (format.Alignment == StringAlignment.Near)
					{
						position.X = empty.X + (ef4.Width / 2f);
					}
					else if (format.Alignment == StringAlignment.Far)
					{
						position.X = empty.Right - (ef4.Width / 2f);
					}
					else
					{
						position.X = (empty.Left + empty.Right) / 2f;
					}
					if (format.LineAlignment == StringAlignment.Near)
					{
						position.Y = empty.Top + (ef4.Height / 2f);
					}
					else if (format.LineAlignment == StringAlignment.Far)
					{
						position.Y = empty.Bottom - (ef4.Height / 2f);
					}
					else
					{
						position.Y = (empty.Bottom + empty.Top) / 2f;
					}
					format.Alignment = StringAlignment.Center;
					format.LineAlignment = StringAlignment.Center;
					int labelAngle = dataPoint.LabelAngle;
					Point3D[] points = new Point3D[] { new Point3D(position.X, position.Y, pointEx.zPosition + pointEx.depth), new Point3D(position.X - 20f, position.Y, pointEx.zPosition + pointEx.depth) };
					area.matrix3D.TransformPoints(points);
					position = points[0].PointF;
					switch (labelAngle)
					{
						case 0:
						case 180:
							{
								points[0].PointF = graph.GetAbsolutePoint(points[0].PointF);
								points[1].PointF = graph.GetAbsolutePoint(points[1].PointF);
								float num3 = (float)Math.Atan((double)((points[1].Y - points[0].Y) / (points[1].X - points[0].X)));
								num3 = (float)Math.Round((double)((num3 * 180f) / 3.141593f));
								labelAngle += (int)num3;
								break;
							}
					}
					RectangleF backPosition = RectangleF.Empty;
					if ((common.ProcessModeRegions || !dataPoint.LabelBackColor.IsEmpty) || !dataPoint.LabelBorderColor.IsEmpty)
					{
						SizeF ef6 = new SizeF(ef4.Width, ef4.Height);
						ef6.Height += ef6.Height / 8f;
						ef6.Width += ef6.Width / ((float)str.Length);
						backPosition = new RectangleF(position.X - (ef6.Width / 2f), position.Y - (ef6.Height / 2f), ef6.Width, ef6.Height);
					}
					using (Brush brush = new SolidBrush(dataPoint.LabelForeColor))
					{
						graph.DrawPointLabelStringRel(common, str, dataPoint.Font, brush, position, format, labelAngle, backPosition, dataPoint.LabelBackColor, dataPoint.LabelBorderColor, dataPoint.LabelBorderWidth, dataPoint.LabelBorderDashStyle, ser, dataPoint, pointIndex);
					}
				}
			}
		}

		private void DrawLabelsAndMarkers(ChartArea area, ChartGraphics graph, CommonElements common, RectangleF rectSize, DataPoint point, Series ser, double barStartPosition, double barSize, double width, int pointIndex, ref int markerIndex)
		{
			SizeF empty = SizeF.Empty;
			if ((point.MarkerStyle != MarkerStyle.None) || (point.MarkerImage.Length > 0))
			{
				if (markerIndex == 0)
				{
					if (point.MarkerImage.Length == 0)
					{
						empty.Width = point.MarkerSize;
						empty.Height = point.MarkerSize;
					}
					else
					{
						common.ImageLoader.GetAdjustedImageSize(point.MarkerImage, graph.Graphics, ref empty);
					}
					empty = graph.GetRelativeSize(empty);
					PointF tf = PointF.Empty;
					if (barStartPosition < barSize)
					{
						tf.X = rectSize.Right;
					}
					else
					{
						tf.X = rectSize.X;
					}
					tf.Y = rectSize.Y + (rectSize.Height / 2f);
					if (common.ProcessModePaint)
					{
						graph.DrawMarkerRel(tf, point.MarkerStyle, GetAdjustedPixelSize(point.MarkerSize, graph), (point.MarkerColor == Color.Empty) ? point.Color : point.MarkerColor, point.MarkerBorderColor, point.MarkerBorderWidth, point.MarkerImage, point.MarkerImageTransparentColor, (point.series != null) ? point.series.ShadowOffset : 0, (point.series != null) ? point.series.ShadowColor : Color.Empty, RectangleF.Empty);
					}
					if (common.ProcessModeRegions)
					{
						this.SetHotRegions(common, graph, point, empty, point.series.Name, pointIndex, point.MarkerStyle, tf);
					}
				}
				markerIndex++;
				if (ser.MarkerStep == markerIndex)
				{
					markerIndex = 0;
				}
			}
			if ((point.Label.Length > 0) || (!point.IsEmpty && (ser.IsValueShownAsLabel || point.IsValueShownAsLabel)))
			{
				RectangleF position = RectangleF.Empty;
				using (StringFormat format = new StringFormat())
				{
					string str;
					if (point.Label.Length == 0)
					{
						str = ValueConverter.FormatValue(ser.Chart, point, point.Tag, this.GetYValue(common, area, ser, point, pointIndex, 0), point.LabelFormat, ser.YValueType, ChartElementType.DataPoint);
					}
					else
					{
						str = point.ReplaceKeywords(point.Label);
					}
					BarValueLabelDrawingStyle defLabelDrawingStyle = this.defLabelDrawingStyle;
					string strA = "";
					if (point.IsCustomPropertySet("BarLabelStyle"))
					{
						strA = point["BarLabelStyle"];
					}
					else if (ser.IsCustomPropertySet("BarLabelStyle"))
					{
						strA = ser["BarLabelStyle"];
					}
					if (strA.Length > 0)
					{
						if (string.Compare(strA, "Left", StringComparison.OrdinalIgnoreCase) == 0)
						{
							defLabelDrawingStyle = BarValueLabelDrawingStyle.Left;
						}
						if (string.Compare(strA, "Right", StringComparison.OrdinalIgnoreCase) == 0)
						{
							defLabelDrawingStyle = BarValueLabelDrawingStyle.Right;
						}
						if (string.Compare(strA, "Center", StringComparison.OrdinalIgnoreCase) == 0)
						{
							defLabelDrawingStyle = BarValueLabelDrawingStyle.Center;
						}
						else if (string.Compare(strA, "Outside", StringComparison.OrdinalIgnoreCase) == 0)
						{
							defLabelDrawingStyle = BarValueLabelDrawingStyle.Outside;
						}
					}
					bool flag = false;
					bool flag2 = false;
					bool flag3 = false;
					float num = 0f;
					while (!flag)
					{
						format.Alignment = StringAlignment.Near;
						format.LineAlignment = StringAlignment.Center;
						if (barStartPosition <= barSize)
						{
							position.X = rectSize.Right;
							position.Width = area.PlotAreaPosition.Right - rectSize.Right;
							if ((position.Width < 0.001f) && (barStartPosition == barSize))
							{
								position.Width = rectSize.X - area.PlotAreaPosition.X;
								position.X = area.PlotAreaPosition.X;
								format.Alignment = StringAlignment.Far;
							}
						}
						else
						{
							position.X = area.PlotAreaPosition.X;
							position.Width = rectSize.X - area.PlotAreaPosition.X;
						}
						position.Y = rectSize.Y - (((float)width) / 2f);
						position.Height = rectSize.Height + ((float)width);
						switch (defLabelDrawingStyle)
						{
							case BarValueLabelDrawingStyle.Outside:
								if (!empty.IsEmpty)
								{
									position.Width -= Math.Min(position.Width, empty.Width / 2f);
									if (barStartPosition < barSize)
									{
										position.X += Math.Min(position.Width, empty.Width / 2f);
									}
								}
								break;

							case BarValueLabelDrawingStyle.Left:
								position = rectSize;
								format.Alignment = StringAlignment.Near;
								break;

							case BarValueLabelDrawingStyle.Center:
								position = rectSize;
								format.Alignment = StringAlignment.Center;
								break;

							case BarValueLabelDrawingStyle.Right:
								position = rectSize;
								format.Alignment = StringAlignment.Far;
								if (!empty.IsEmpty)
								{
									position.Width -= Math.Min(position.Width, empty.Width / 2f);
									if (barStartPosition >= barSize)
									{
										position.X += Math.Min(position.Width, empty.Width / 2f);
									}
								}
								break;
						}
						if (barStartPosition > barSize)
						{
							if (format.Alignment == StringAlignment.Far)
							{
								format.Alignment = StringAlignment.Near;
							}
							else if (format.Alignment == StringAlignment.Near)
							{
								format.Alignment = StringAlignment.Far;
							}
						}
						SizeF ef3 = graph.MeasureStringRel(str, point.Font);
						if ((!flag2 && !flag3) && (ef3.Width > (position.Width - 1f)))
						{
							flag2 = true;
							num = position.Width;
							if (defLabelDrawingStyle == BarValueLabelDrawingStyle.Outside)
							{
								defLabelDrawingStyle = BarValueLabelDrawingStyle.Right;
							}
							else
							{
								defLabelDrawingStyle = BarValueLabelDrawingStyle.Outside;
							}
						}
						else
						{
							if ((flag2 && !flag3) && ((ef3.Width > (position.Width - 1f)) && (num > position.Width)))
							{
								flag3 = true;
								if (defLabelDrawingStyle == BarValueLabelDrawingStyle.Outside)
								{
									defLabelDrawingStyle = BarValueLabelDrawingStyle.Right;
								}
								else
								{
									defLabelDrawingStyle = BarValueLabelDrawingStyle.Outside;
								}
								continue;
							}
							flag = true;
						}
					}
					RectangleF backPosition = RectangleF.Empty;
					if (((common.ProcessModeRegions || !point.LabelBackColor.IsEmpty) || !point.LabelBorderColor.IsEmpty) && ((position.Width > 0f) && (position.Height > 0f)))
					{
						SizeF ef5 = graph.MeasureStringRel(str, point.Font);
						ef5.Height += ef5.Height / 8f;
						float num2 = (ef5.Width / ((float)str.Length)) / 2f;
						ef5.Width += num2;
						backPosition = new RectangleF(position.X, position.Y + ((position.Height - ef5.Height) / 2f), ef5.Width, ef5.Height);
						if (format.Alignment == StringAlignment.Near)
						{
							backPosition.X += num2 / 2f;
							position.X += num2;
						}
						else if (format.Alignment == StringAlignment.Center)
						{
							backPosition.X = position.X + ((position.Width - ef5.Width) / 2f);
						}
						else if (format.Alignment == StringAlignment.Far)
						{
							backPosition.X = (position.Right - ef5.Width) - (num2 / 2f);
							position.X -= num2;
						}
					}
					SizeF ef6 = graph.MeasureStringRel(str, point.Font);
					if (ef6.Height > position.Height)
					{
						position.Y -= (ef6.Height - position.Height) / 2f;
						position.Height = ef6.Height;
					}
					using (Brush brush = new SolidBrush(point.LabelForeColor))
					{
						graph.DrawPointLabelStringRel(common, str, point.Font, brush, position, format, point.LabelAngle, backPosition, point.LabelBackColor, point.LabelBorderColor, point.LabelBorderWidth, point.LabelBorderDashStyle, ser, point, pointIndex);
					}
				}
			}
		}

		private void DrawMarkers3D(ChartArea area, ChartGraphics graph, CommonElements common, RectangleF rectSize, DataPoint3D pointEx, Series ser, double barStartPosition, double barSize)
		{
			DataPoint dataPoint = pointEx.dataPoint;
			SizeF empty = SizeF.Empty;
			if (((dataPoint.MarkerStyle != MarkerStyle.None) || (dataPoint.MarkerImage.Length > 0)) && ((pointEx.index % ser.MarkerStep) == 0))
			{
				if (dataPoint.MarkerImage.Length == 0)
				{
					empty.Width = dataPoint.MarkerSize;
					empty.Height = dataPoint.MarkerSize;
				}
				else
				{
					common.ImageLoader.GetAdjustedImageSize(dataPoint.MarkerImage, graph.Graphics, ref empty);
				}
				empty = graph.GetRelativeSize(empty);
				PointF point = PointF.Empty;
				if (barStartPosition < barSize)
				{
					point.X = rectSize.Right;
				}
				else
				{
					point.X = rectSize.X;
				}
				point.Y = rectSize.Y + (rectSize.Height / 2f);
				Point3D[] points = new Point3D[] { new Point3D(point.X, point.Y, pointEx.zPosition + (pointEx.depth / 2f)) };
				area.matrix3D.TransformPoints(points);
				graph.DrawMarker3D(area.matrix3D, area.Area3DStyle.LightStyle, pointEx.zPosition + (pointEx.depth / 2f), point, dataPoint.MarkerStyle, GetAdjustedPixelSize(dataPoint.MarkerSize, graph), dataPoint.MarkerColor.IsEmpty ? dataPoint.series.Color : dataPoint.MarkerColor, dataPoint.MarkerBorderColor, dataPoint.MarkerBorderWidth, dataPoint.MarkerImage, dataPoint.MarkerImageTransparentColor, (dataPoint.series != null) ? dataPoint.series.ShadowOffset : 0, (dataPoint.series != null) ? dataPoint.series.ShadowColor : Color.Empty, RectangleF.Empty, DrawingOperationTypes.DrawElement);
			}
		}

		private static int GetAdjustedPixelSize(int pixelSize, ChartGraphics graph)
		{
			if ((graph != null) && (graph.Graphics != null))
			{
				SizeF ef = new SizeF();
				ef.Width = (pixelSize * graph.Graphics.DpiX) / 96f;
				ef.Height = (pixelSize * graph.Graphics.DpiY) / 96f;
				pixelSize = (int)Math.Max(ef.Width, ef.Height);
			}
			return pixelSize;
		}

		internal double GetEmptyPointValue(DataPoint point, int pointIndex, int yValueIndex)
		{
			Series series = point.series;
			double d = 0.0;
			double naN = 0.0;
			int num3 = 0;
			int num4 = series.Points.Count - 1;
			string strA = "";
			if (series.EmptyPointStyle.IsCustomPropertySet("EmptyPointValue"))
			{
				strA = series.EmptyPointStyle["EmptyPointValue"];
			}
			else if (series.IsCustomPropertySet("EmptyPointValue"))
			{
				strA = series["EmptyPointValue"];
			}
			if (string.Compare(strA, "Zero", StringComparison.OrdinalIgnoreCase) == 0)
			{
				return 0.0;
			}
			for (int i = pointIndex; i >= 0; i--)
			{
				if (!series.Points[i].IsEmpty)
				{
					d = series.Points[i].YValues[yValueIndex];
					num3 = i;
					break;
				}
				d = double.NaN;
			}
			for (int j = pointIndex; j < series.Points.Count; j++)
			{
				if (!series.Points[j].IsEmpty)
				{
					naN = series.Points[j].YValues[yValueIndex];
					num4 = j;
					break;
				}
				naN = double.NaN;
			}
			if (double.IsNaN(d))
			{
				if (double.IsNaN(naN))
				{
					d = 0.0;
				}
				else
				{
					d = naN;
				}
			}
			if (double.IsNaN(naN))
			{
				naN = d;
			}
			if (series.Points[num4].XValue == series.Points[num3].XValue)
			{
				return ((d + naN) / 2.0);
			}
			double num7 = (d - naN) / (series.Points[num4].XValue - series.Points[num3].XValue);
			return ((-num7 * (point.XValue - series.Points[num3].XValue)) + d);
		}

		public virtual Image GetImage(ChartTypeRegistry registry)
		{
			return (Image)registry.ResourceManager.GetObject(this.Name + "ChartType");
		}

		public LegendImageStyle GetLegendImageStyle(Series series)
		{
			return LegendImageStyle.Rectangle;
		}

		public virtual double GetYValue(CommonElements common, ChartArea area, Series series, DataPoint point, int pointIndex, int yValueIndex)
		{
			if (yValueIndex == -1)
			{
				return 0.0;
			}
			if (point.YValues.Length <= yValueIndex)
			{
				throw new InvalidOperationException(SR.ExceptionChartTypeRequiresYValues(this.Name, this.YValuesPerPoint.ToString(CultureInfo.InvariantCulture)));
			}
			if (!point.IsEmpty && !double.IsNaN(point.YValues[yValueIndex]))
			{
				return point.YValues[yValueIndex];
			}
			double num = this.GetEmptyPointValue(point, pointIndex, yValueIndex);
			if (num == 0.0)
			{
				Axis axis = area.GetAxis(AxisName.Y, series.YAxisType, series.YSubAxisName);
				double maximum = axis.maximum;
				double minimum = axis.minimum;
				if (num < minimum)
				{
					return minimum;
				}
				if (num > maximum)
				{
					num = maximum;
				}
			}
			return num;
		}

		public void Paint(ChartGraphics graph, CommonElements common, ChartArea area, Series seriesToDraw)
		{
			this.pointLabelsMarkersPresent = false;
			this.ProcessChartType(false, false, graph, common, area, seriesToDraw);
			if (this.pointLabelsMarkersPresent)
			{
				this.ProcessChartType(true, false, graph, common, area, seriesToDraw);
			}
		}

		private void ProcessChartType(bool labels, bool selection, ChartGraphics graph, CommonElements common, ChartArea area, Series seriesToDraw)
		{
			int num = 0;
			bool sameInterval = false;
			SizeF relativeSize = graph.GetRelativeSize(new SizeF(1.1f, 1.1f));
			if (area.Area3DStyle.Enable3D)
			{
				this.ProcessChartType3D(selection, graph, common, area, seriesToDraw);
			}
			else
			{
				List<string> seriesFromChartType = area.GetSeriesFromChartType(this.Name);
				bool drawSeriesSideBySide = this.drawSeriesSideBySide;
				foreach (string str in seriesFromChartType)
				{
					if (common.DataManager.Series[str].IsCustomPropertySet("DrawSideBySide"))
					{
						string strA = common.DataManager.Series[str]["DrawSideBySide"];
						if (string.Compare(strA, "False", StringComparison.OrdinalIgnoreCase) == 0)
						{
							drawSeriesSideBySide = false;
						}
						else
						{
							if (string.Compare(strA, "True", StringComparison.OrdinalIgnoreCase) == 0)
							{
								drawSeriesSideBySide = true;
								continue;
							}
							if (string.Compare(strA, "Auto", StringComparison.OrdinalIgnoreCase) != 0)
							{
								throw new InvalidOperationException(SR.ExceptionAttributeDrawSideBySideInvalid);
							}
						}
					}
				}
				int count = seriesFromChartType.Count;
				if (!drawSeriesSideBySide)
				{
					count = 1;
				}
				bool flag3 = ChartHelper.IndexedSeries(area.Common, seriesFromChartType.ToArray());
				foreach (Series series in common.DataManager.Series)
				{
					if (((string.Compare(series.ChartTypeName, this.Name, true, CultureInfo.CurrentCulture) != 0) || (series.ChartArea != area.Name)) || ((series.Points.Count == 0) || !series.IsVisible()))
					{
						continue;
					}
					Axis axis = area.GetAxis(AxisName.X, series.XAxisType, series.XSubAxisName);
					double viewMaximum = axis.ViewMaximum;
					double viewMinimum = axis.ViewMinimum;
					Axis axis2 = area.GetAxis(AxisName.Y, series.YAxisType, series.YSubAxisName);
					double num5 = axis2.ViewMaximum;
					double num6 = axis2.ViewMinimum;
					double interval = 1.0;
					if (!flag3)
					{
						if ((series.Points.Count == 1) && (((series.XValueType == ChartValueType.Date) || (series.XValueType == ChartValueType.DateTime)) || ((series.XValueType == ChartValueType.Time) || (series.XValueType == ChartValueType.DateTimeOffset))))
						{
							area.GetPointsInterval(seriesFromChartType, axis.IsLogarithmic, axis.logarithmBase, true, out sameInterval);
							if (!double.IsNaN(axis.majorGrid.GetInterval()) && (axis.majorGrid.GetIntervalType() != DateTimeIntervalType.NotSet))
							{
								interval = ChartHelper.GetIntervalSize(axis.minimum, axis.majorGrid.GetInterval(), axis.majorGrid.GetIntervalType());
							}
							else
							{
								interval = ChartHelper.GetIntervalSize(axis.minimum, axis.Interval, axis.IntervalType);
							}
						}
						else
						{
							interval = area.GetPointsInterval(seriesFromChartType, axis.IsLogarithmic, axis.logarithmBase, true, out sameInterval);
						}
					}
					double width = series.GetPointWidth(graph, axis, interval, 0.8) / ((double)count);
					if (!selection)
					{
						common.Chart.CallOnPrePaint(new ChartPaintEventArgs(series, graph, common, area.PlotAreaPosition));
					}
					int pointIndex = 0;
					int markerIndex = 0;
					foreach (DataPoint point in series.Points)
					{
						if (point.YValues.Length < this.YValuesPerPoint)
						{
							throw new InvalidOperationException(SR.ExceptionChartTypeRequiresYValues(this.Name, this.YValuesPerPoint.ToString(CultureInfo.InvariantCulture)));
						}
						point.positionRel = new PointF(float.NaN, float.NaN);
						double logValue = axis2.GetLogValue(this.GetYValue(common, area, series, point, pointIndex, this.useTwoValues ? 1 : 0));
						bool flag4 = false;
						bool flag5 = true;
						if (((decimal)logValue) > ((decimal)num5))
						{
							logValue = num5;
							flag4 = true;
						}
						else if (((decimal)logValue) < ((decimal)num6))
						{
							logValue = num6;
							flag4 = true;
						}
						double linearPosition = axis2.GetLinearPosition(logValue);
						double barStartPosition = 0.0;
						if (this.useTwoValues)
						{
							double axisValue = axis2.GetLogValue(this.GetYValue(common, area, series, point, pointIndex, 0));
							flag5 = false;
							if (((decimal)axisValue) > ((decimal)num5))
							{
								axisValue = num5;
								flag5 = true;
							}
							else if (((decimal)axisValue) < ((decimal)num6))
							{
								axisValue = num6;
								flag5 = true;
							}
							barStartPosition = axis2.GetLinearPosition(axisValue);
						}
						else
						{
							barStartPosition = axis2.GetPosition(axis2.Crossing);
						}
						double position = 0.0;
						if (flag3)
						{
							position = ((axis.GetPosition(pointIndex + 1.0) - ((width * count) / 2.0)) + (width / 2.0)) + (num * width);
						}
						else if (sameInterval)
						{
							position = ((axis.GetPosition(point.XValue) - ((width * count) / 2.0)) + (width / 2.0)) + (num * width);
						}
						else
						{
							position = axis.GetPosition(point.XValue);
						}
						if ((linearPosition < barStartPosition) && ((barStartPosition - linearPosition) < relativeSize.Width))
						{
							linearPosition = barStartPosition - relativeSize.Width;
						}
						if ((linearPosition > barStartPosition) && ((linearPosition - barStartPosition) < relativeSize.Width))
						{
							linearPosition = barStartPosition + relativeSize.Width;
						}
						RectangleF empty = RectangleF.Empty;
						try
						{
							empty.Y = (float)(position - (width / 2.0));
							empty.Height = (float)width;
							if (barStartPosition < linearPosition)
							{
								empty.X = (float)barStartPosition;
								empty.Width = ((float)linearPosition) - empty.X;
							}
							else
							{
								empty.X = (float)linearPosition;
								empty.Width = ((float)barStartPosition) - empty.X;
							}
						}
						catch (OverflowException)
						{
							pointIndex++;
							continue;
						}
						point.positionRel = new PointF((barStartPosition < linearPosition) ? empty.Right : empty.X, (float)position);
						if (common.ProcessModePaint)
						{
							if (!point.IsEmpty && !labels)
							{
								double yValue = flag3 ? ((double)(pointIndex + 1)) : point.XValue;
								yValue = axis.GetLogValue(yValue);
								if ((yValue < viewMinimum) || (yValue > viewMaximum))
								{
									pointIndex++;
									continue;
								}
								bool flag6 = false;
								if ((empty.Y < area.PlotAreaPosition.Y) || (empty.Bottom > area.PlotAreaPosition.Bottom))
								{
									graph.SetClip(area.PlotAreaPosition.ToRectangleF());
									flag6 = true;
								}
								graph.StartHotRegion(point);
								graph.FillRectangleRel(empty, point.Color, point.BackHatchStyle, point.BackImage, point.BackImageWrapMode, point.BackImageTransparentColor, point.BackImageAlignment, point.BackGradientStyle, point.BackSecondaryColor, point.BorderColor, point.BorderWidth, point.BorderDashStyle, series.ShadowColor, series.ShadowOffset, PenAlignment.Inset, ChartGraphics.GetBarDrawingStyle(point), false);
								graph.EndHotRegion();
								if (flag6)
								{
									graph.ResetClip();
								}
								if (common.ProcessModeRegions)
								{
									common.HotRegionsList.AddHotRegion(empty, point, series.Name, pointIndex);
								}
							}
							if (((!flag4 || !flag5) || (empty.Width != 0f)) && (((empty.Y + (empty.Height / 2f)) >= area.PlotAreaPosition.Y) && ((empty.Y + (empty.Height / 2f)) <= area.PlotAreaPosition.Bottom)))
							{
								if (labels)
								{
									this.DrawLabelsAndMarkers(area, graph, common, empty, point, series, barStartPosition, linearPosition, width, pointIndex, ref markerIndex);
								}
								else if ((point.MarkerStyle != MarkerStyle.None) || (point.MarkerImage.Length > 0))
								{
									this.pointLabelsMarkersPresent = true;
								}
								else if ((series.IsValueShownAsLabel || point.IsValueShownAsLabel) || (point.Label.Length > 0))
								{
									this.pointLabelsMarkersPresent = true;
								}
							}
						}
						if (common.ProcessModeRegions && !common.ProcessModePaint)
						{
							common.HotRegionsList.AddHotRegion(empty, point, series.Name, pointIndex);
							if (labels)
							{
								this.DrawLabelsAndMarkers(area, graph, common, empty, point, series, barStartPosition, linearPosition, width, pointIndex, ref markerIndex);
							}
						}
						pointIndex++;
					}
					if (!selection)
					{
						common.Chart.CallOnPostPaint(new ChartPaintEventArgs(series, graph, common, area.PlotAreaPosition));
					}
					if (drawSeriesSideBySide)
					{
						num++;
					}
				}
			}
		}

		private void ProcessChartType3D(bool selection, ChartGraphics graph, CommonElements common, ChartArea area, Series seriesToDraw)
		{
			SizeF relativeSize = graph.GetRelativeSize(new SizeF(1.1f, 1.1f));
			double yValue = 0.0;
			List<string> seriesNamesList = null;
			bool drawSeriesSideBySide = this.drawSeriesSideBySide;
			if ((!area.Area3DStyle.IsClustered || !this.SideBySideSeries) && !this.Stacked)
			{
				seriesNamesList = new List<string>();
				seriesNamesList.Add(seriesToDraw.Name);
			}
			else
			{
				seriesNamesList = area.GetSeriesFromChartType(this.Name);
				foreach (string str in seriesNamesList)
				{
					if (common.DataManager.Series[str].IsCustomPropertySet("DrawSideBySide"))
					{
						string strA = common.DataManager.Series[str]["DrawSideBySide"];
						if (string.Compare(strA, "False", StringComparison.OrdinalIgnoreCase) == 0)
						{
							drawSeriesSideBySide = false;
						}
						else
						{
							if (string.Compare(strA, "True", StringComparison.OrdinalIgnoreCase) == 0)
							{
								drawSeriesSideBySide = true;
								continue;
							}
							if (string.Compare(strA, "Auto", StringComparison.OrdinalIgnoreCase) != 0)
							{
								throw new InvalidOperationException(SR.ExceptionAttributeDrawSideBySideInvalid);
							}
						}
					}
				}
			}
			ArrayList list2 = area.GetDataPointDrawingOrder(seriesNamesList, this, selection, COPCoordinates.Y | COPCoordinates.X, new BarPointsDrawingOrderComparer(area, selection, COPCoordinates.Y | COPCoordinates.X), 0, drawSeriesSideBySide);
			bool flag2 = false;
			foreach (object obj2 in list2)
			{
				DataPoint3D pointEx = (DataPoint3D)obj2;
				DataPoint dataPoint = pointEx.dataPoint;
				Series series = dataPoint.series;
				if (dataPoint.YValues.Length < this.YValuesPerPoint)
				{
					throw new InvalidOperationException(SR.ExceptionChartTypeRequiresYValues(this.Name, this.YValuesPerPoint.ToString(CultureInfo.InvariantCulture)));
				}
				dataPoint.positionRel = new PointF(float.NaN, float.NaN);
				Axis axis = area.GetAxis(AxisName.X, series.XAxisType, series.XSubAxisName);
				Axis axis2 = area.GetAxis(AxisName.Y, series.YAxisType, series.YSubAxisName);
				BarDrawingStyle barDrawingStyle = ChartGraphics.GetBarDrawingStyle(dataPoint);
				float topRightDarkening = 0f;
				float bottomLeftDarkening = 0f;
				double logValue = axis2.GetLogValue(this.GetYValue(common, area, series, pointEx.dataPoint, pointEx.index - 1, this.useTwoValues ? 1 : 0));
				if (logValue > axis2.ViewMaximum)
				{
					topRightDarkening = 0.5f;
					logValue = axis2.ViewMaximum;
				}
				else if (logValue < axis2.ViewMinimum)
				{
					topRightDarkening = 0.5f;
					logValue = axis2.ViewMinimum;
				}
				double linearPosition = axis2.GetLinearPosition(logValue);
				double barStartPosition = 0.0;
				if (this.useTwoValues)
				{
					double axisValue = axis2.GetLogValue(this.GetYValue(common, area, series, pointEx.dataPoint, pointEx.index - 1, 0));
					if (axisValue > axis2.ViewMaximum)
					{
						bottomLeftDarkening = 0.5f;
						axisValue = axis2.ViewMaximum;
					}
					else if (axisValue < axis2.ViewMinimum)
					{
						bottomLeftDarkening = 0.5f;
						axisValue = axis2.ViewMinimum;
					}
					barStartPosition = axis2.GetLinearPosition(axisValue);
				}
				else
				{
					barStartPosition = axis2.GetPosition(axis2.Crossing);
				}
				double xPosition = pointEx.xPosition;
				if ((linearPosition < barStartPosition) && ((barStartPosition - linearPosition) < relativeSize.Width))
				{
					linearPosition = barStartPosition - relativeSize.Width;
				}
				if ((linearPosition > barStartPosition) && ((linearPosition - barStartPosition) < relativeSize.Width))
				{
					linearPosition = barStartPosition + relativeSize.Width;
				}
				RectangleF empty = RectangleF.Empty;
				try
				{
					empty.Y = (float)(xPosition - (pointEx.width / 2.0));
					empty.Height = (float)pointEx.width;
					if (barStartPosition < linearPosition)
					{
						empty.X = (float)barStartPosition;
						empty.Width = ((float)linearPosition) - empty.X;
					}
					else
					{
						float num9 = topRightDarkening;
						topRightDarkening = bottomLeftDarkening;
						bottomLeftDarkening = num9;
						empty.X = (float)linearPosition;
						empty.Width = ((float)barStartPosition) - empty.X;
					}
				}
				catch (OverflowException)
				{
					continue;
				}
				dataPoint.positionRel = new PointF(empty.Right, (float)xPosition);
				GraphicsPath path = null;
				if (!dataPoint.IsEmpty)
				{
					yValue = pointEx.indexedSeries ? ((double)pointEx.index) : dataPoint.XValue;
					yValue = axis.GetLogValue(yValue);
					if ((yValue < axis.ViewMinimum) || (yValue > axis.ViewMaximum))
					{
						continue;
					}
					bool flag3 = false;
					if ((empty.Bottom <= area.PlotAreaPosition.Y) || (empty.Y >= area.PlotAreaPosition.Bottom))
					{
						continue;
					}
					if (empty.Y < area.PlotAreaPosition.Y)
					{
						empty.Height -= area.PlotAreaPosition.Y - empty.Y;
						empty.Y = area.PlotAreaPosition.Y;
					}
					if (empty.Bottom > area.PlotAreaPosition.Bottom)
					{
						empty.Height -= empty.Bottom - area.PlotAreaPosition.Bottom;
					}
					if (empty.Height < 0f)
					{
						empty.Height = 0f;
					}
					if ((empty.Height == 0f) || (empty.Width == 0f))
					{
						continue;
					}
					DrawingOperationTypes drawElement = DrawingOperationTypes.DrawElement;
					if (common.ProcessModeRegions)
					{
						drawElement |= DrawingOperationTypes.CalcElementPath;
					}
					graph.StartHotRegion(dataPoint);
					path = graph.Fill3DRectangle(empty, pointEx.zPosition, pointEx.depth, area.matrix3D, area.Area3DStyle.LightStyle, dataPoint.Color, topRightDarkening, bottomLeftDarkening, dataPoint.BorderColor, dataPoint.BorderWidth, dataPoint.BorderDashStyle, barDrawingStyle, false, drawElement);
					graph.EndHotRegion();
					if (flag3)
					{
						graph.ResetClip();
					}
				}
				this.DrawMarkers3D(area, graph, common, empty, pointEx, series, barStartPosition, linearPosition);
				if (dataPoint.IsValueShownAsLabel || (dataPoint.Label.Length > 0))
				{
					flag2 = true;
				}
				if (common.ProcessModeRegions)
				{
					common.HotRegionsList.AddHotRegion(path, false, graph, dataPoint, series.Name, pointEx.index - 1);
				}
				if (path != null)
				{
					path.Dispose();
				}
			}
			if (flag2)
			{
				foreach (object obj3 in list2)
				{
					DataPoint3D pointd2 = (DataPoint3D)obj3;
					DataPoint point2 = pointd2.dataPoint;
					Series series2 = point2.series;
					Axis axis3 = area.GetAxis(AxisName.X, series2.XAxisType, series2.XSubAxisName);
					Axis axis4 = area.GetAxis(AxisName.Y, series2.YAxisType, series2.YSubAxisName);
					double viewMaximum = axis4.GetLogValue(this.GetYValue(common, area, series2, pointd2.dataPoint, pointd2.index - 1, this.useTwoValues ? 1 : 0));
					if (viewMaximum > axis4.ViewMaximum)
					{
						viewMaximum = axis4.ViewMaximum;
					}
					else if (viewMaximum < axis4.ViewMinimum)
					{
						viewMaximum = axis4.ViewMinimum;
					}
					double barSize = axis4.GetLinearPosition(viewMaximum);
					double position = 0.0;
					if (this.useTwoValues)
					{
						double viewMinimum = axis4.GetLogValue(this.GetYValue(common, area, series2, pointd2.dataPoint, pointd2.index - 1, 0));
						if (viewMinimum > axis4.ViewMaximum)
						{
							viewMinimum = axis4.ViewMaximum;
						}
						else if (viewMinimum < axis4.ViewMinimum)
						{
							viewMinimum = axis4.ViewMinimum;
						}
						position = axis4.GetLinearPosition(viewMinimum);
					}
					else
					{
						position = axis4.GetPosition(axis4.Crossing);
					}
					double num14 = pointd2.xPosition;
					RectangleF rectSize = RectangleF.Empty;
					try
					{
						rectSize.Y = (float)(num14 - (pointd2.width / 2.0));
						rectSize.Height = (float)pointd2.width;
						if (position < barSize)
						{
							rectSize.X = (float)position;
							rectSize.Width = ((float)barSize) - rectSize.X;
						}
						else
						{
							rectSize.X = (float)barSize;
							rectSize.Width = ((float)position) - rectSize.X;
						}
					}
					catch (OverflowException)
					{
						continue;
					}
					if (!point2.IsEmpty)
					{
						yValue = pointd2.indexedSeries ? ((double)pointd2.index) : point2.XValue;
						yValue = axis3.GetLogValue(yValue);
						if (((yValue < axis3.ViewMinimum) || (yValue > axis3.ViewMaximum)) || ((((decimal)rectSize.Y) < ((decimal)area.PlotAreaPosition.Y)) || (((decimal)rectSize.Bottom) > ((decimal)area.PlotAreaPosition.Bottom))))
						{
							continue;
						}
						this.DrawLabels3D(area, graph, common, rectSize, pointd2, series2, position, barSize, pointd2.width, pointd2.index - 1);
					}
				}
			}
		}

		private void SetHotRegions(CommonElements common, ChartGraphics graph, DataPoint point, SizeF markerSize, string seriesName, int pointIndex, MarkerStyle pointMarkerStyle, PointF markerPosition)
		{
			SizeF ef = markerSize;
			int insertIndex = common.HotRegionsList.FindInsertIndex();
			if (pointMarkerStyle == MarkerStyle.Circle)
			{
				common.HotRegionsList.AddHotRegion(insertIndex, graph, markerPosition.X, markerPosition.Y, ef.Width / 2f, point, seriesName, pointIndex);
			}
			else
			{
				common.HotRegionsList.AddHotRegion(new RectangleF(markerPosition.X - (ef.Width / 2f), markerPosition.Y - (ef.Height / 2f), ef.Width, ef.Height), point, seriesName, pointIndex);
			}
		}

		public bool ApplyPaletteColorsToPoints
		{
			get
			{
				return false;
			}
		}

		public bool CircularChartArea
		{
			get
			{
				return false;
			}
		}

		public bool DataPointsInLegend
		{
			get
			{
				return false;
			}
		}

		public virtual bool ExtraYValuesConnectedToYAxis
		{
			get
			{
				return false;
			}
		}

		public virtual bool HundredPercent
		{
			get
			{
				return false;
			}
		}

		public virtual bool HundredPercentSupportNegative
		{
			get
			{
				return false;
			}
		}

		public virtual string Name
		{
			get
			{
				return "Bar";
			}
		}

		public bool RequireAxes
		{
			get
			{
				return true;
			}
		}

		public bool SecondYScale
		{
			get
			{
				return false;
			}
		}

		public virtual bool SideBySideSeries
		{
			get
			{
				return true;
			}
		}

		public bool Stacked
		{
			get
			{
				return false;
			}
		}

		public bool StackSign
		{
			get
			{
				return false;
			}
		}

		public bool SupportLogarithmicAxes
		{
			get
			{
				return true;
			}
		}

		public virtual bool SupportStackedGroups
		{
			get
			{
				return false;
			}
		}

		public bool SwitchValueAxes
		{
			get
			{
				return true;
			}
		}

		public virtual int YValuesPerPoint
		{
			get
			{
				return 1;
			}
		}

		public virtual bool ZeroCrossing
		{
			get
			{
				return true;
			}
		}
	}
}

